using Fine.Collections.Cont;
using Fine.Collections.Intf;
using Fine.TestUtils;
using NUnit.Framework;



namespace Fine.Collections.Views
{
    [TestFixture]
    public class RRandomListAdaptor_test
    {

        [Test]
        public void Test_FirstLast()
        {
            var adaptor = MakeSimpleListAndAdapter();

            adaptor.FirstIndex  ._equals_(101);
            adaptor.LastIndex   ._equals_(103);

            adaptor.First       ._equals_("100001");
            adaptor.Last        ._equals_("300003");
        }
        

        [Test]
        public void Test_Indexer()
        {
            var adaptor = MakeSimpleListAndAdapter();

            adaptor[101]      ._equals_("100001");
            adaptor[102]      ._equals_("200002");
            adaptor[103]      ._equals_("300003");
        }
        

        [Test]
        public void Test_IndexOf()
        {
            var adaptor = MakeSimpleListAndAdapter();

            adaptor.IndexOf(x => x[0] == '2')      ._equals_(102);
            adaptor.IndexOf(x => x[0] != '2', 102) ._equals_(103);
        }
        

        [Test]
        public void Test_IndexOf_notFound()
        {
            var adaptor = MakeSimpleListAndAdapter();

            adaptor.IndexOf(x => x[0] == '4')      ._equals_(int.MinValue);
        }
        


        private static RRandomListAdaptor<RRandomList<long>,long,string> MakeSimpleListAndAdapter() 
        {
            var source = new ArrList<long>(101)
                         {
                             100001, 200002, 300003
                         };
            return new RRandomListAdaptor<RRandomList<long>,long,string>(source, x => x.ToString());
        }

    }
}